<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="/WEB-INF/resources/common/basejs.jsp"%>
<title>Insert title here</title>
</head>
<body>
	<input type="text" />
	<a id="send" class="btn btn-info" href="javascript:void(0);">发送</a>
	<a id="send2" class="btn btn-info" href="javascript:void(0);">发送2</a>
	<script language="javascript" type="text/javascript">
		$(function() {
			websocket.init();
			$("#send").click(function(){
				websocket.sendMessage("1111");
			});
			$("#send2").click(function(){
				Util.callAjax("/websocket/send", {},function(){});
			});
		});
		var websocket = {
			connect : '',
			init : function() {
				var t = this;
				if (window.WebSocket != undefined) {
					t.connect = new WebSocket('ws://localhost:8080/hello');
					t.connect.onmessage = t.onMessage;
					t.connect.onerror = t.onError;
				}
			},
			onMessage : function(message) {
				Util.showMessage(message.data)
				console.log("收到消息");
				console.log(message);
			},
			onError : function(e) {
				console.log("发生错误" + e);
			},
			sendMessage : function(message) {
				var t = this;
				t.connect.send(message);

			}

		}
	</script>
</body>
</html>